package csc411;

import java.net.*;

public class Request {

	private InetAddress address;
	private int port;
	private int requestId;
	private String response;
	private boolean hasCompletedExecution;

	// constructor for yet to be completed execution
	public Request(InetAddress address, int port, int requestId) {
		this.address = address;
		this.port = port;
		this.requestId = requestId;
		this.response = "";
		this.hasCompletedExecution = false;
	}

	// constructor for completed execution
	public Request(InetAddress address, int port, int requestId, String response) {
		this.address = address;
		this.port = port;
		this.requestId = requestId;
		this.response = response;
		this.hasCompletedExecution = true;
	}

	public boolean equal(InetAddress address, int port, int requestId) {

		boolean value = false;

		if (this.address.equals(address) && this.port == port && this.requestId == requestId) {

			value = true;
		}

		return value;

	}

	public String setResponse(String response) {
		this.response = response;
		this.hasCompletedExecution = true;
		return this.response;
	}

	public boolean hasCompletedExecution() {
		return this.hasCompletedExecution;
	}

	public InetAddress getAddress() {
		return this.address;
	}

	public int getPort() {
		return this.port;
	}

	public int getRequestId() {
		return this.requestId;
	}

	public String getResponse() {
		return this.response;
	}

	@Override
	public String toString() {
		String value;
		value = this.address.getHostAddress() + ":" + this.port + " (" + this.requestId + ") : " + this.response;

		if (!this.hasCompletedExecution) {
			value = value + " (Executing)";
		}

		return value;
	}
}